package com.hq.ims.userpc.controller;

import com.hq.ims.data.annotation.UserOperationMonitor;
import com.hq.ims.data.entityenum.EnumBusinessTypeStatus;
import com.hq.ims.data.service.BaseBusiInfoService;
import com.hq.ims.data.utils.LocalConstant;
import com.hq.ims.data.utils.WebExpandUtils;
import com.hq.ims.data.vo.BusiInfoMapstruct;
import com.hq.ims.userpc.busservice.ProjectFilingService;
import com.hq.mybatis.base.page.RequestPage;
import com.hq.mybatis.base.page.ReturnPage;
import com.hq.utils.vo.ReturnVo;
import com.hq.web.annotations.GetJsonValue;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author lichaojie
 * @date 2024/10/31 9:37
 * @ClassName ProjectFilingController
 **/@Api(tags = "线下项目备案")
@RestController
@RequestMapping(LocalConstant.SYS_TYPE_USER_PC_URL_PREFIX + "/projectFiling")
public class ProjectFilingController {
     @Resource
     private ProjectFilingService projectFilingService;
     @Resource
     private BaseBusiInfoService baseBusiInfoService;

    @ApiOperation(value = "线下项目备案列表", consumes = MediaType.APPLICATION_JSON_VALUE)
    @UserOperationMonitor
    @ApiImplicitParams({})
    @PostMapping(value = "/getPage", consumes = MediaType.APPLICATION_JSON_VALUE)
    public ReturnVo<ReturnPage> getPage(
            @RequestBody RequestPage page,
            @RequestBody BusiInfoMapstruct.PageSearchVo searchVo
    ) {
        searchVo.setOrgId(WebExpandUtils.getHeadCompanyId());
        searchVo.setInfoType(EnumBusinessTypeStatus.ExternalStatement);
        baseBusiInfoService.getByPage(page,searchVo);
        return ReturnVo.buildSuccess(page.getReturnPage());
    }
    @ApiOperation(value = "项目备案新增", consumes = MediaType.APPLICATION_JSON_VALUE)
    @UserOperationMonitor
    @ApiImplicitParams({})
    @PostMapping(value = "/addData", consumes = MediaType.APPLICATION_JSON_VALUE)
    public ReturnVo<Boolean> addData(@RequestBody BusiInfoMapstruct.SaveVo vo) {
        projectFilingService.addBusiInfo(vo);
        return ReturnVo.buildSuccess(true);
    }

    @ApiOperation(value = "项目备案修改", consumes = MediaType.APPLICATION_JSON_VALUE)
    @UserOperationMonitor
    @ApiImplicitParams({})
    @PostMapping(value = "/updateData", consumes = MediaType.APPLICATION_JSON_VALUE)
    public ReturnVo<Boolean> updateData(@RequestBody BusiInfoMapstruct.SaveVo vo) {
        projectFilingService.editBusiInfo(vo);
        return ReturnVo.buildSuccess(true);
    }

    @ApiOperation(value = "项目备案删除", consumes = MediaType.APPLICATION_JSON_VALUE)
    @UserOperationMonitor
    @ApiImplicitParams({})
    @PostMapping(value = "/deleteData", consumes = MediaType.APPLICATION_JSON_VALUE)
    public ReturnVo<Boolean> deleteData(@GetJsonValue(zh = "数据ID") List<String> busiInfoIds) {
        projectFilingService.deleteDataBatch(busiInfoIds);
        return ReturnVo.buildSuccess(true);
    }

    @ApiOperation(value = "项目备案详情", consumes = MediaType.APPLICATION_JSON_VALUE)
    @ApiImplicitParams({})
    @PostMapping(value = "/getData", consumes = MediaType.APPLICATION_JSON_VALUE)
    public ReturnVo<BusiInfoMapstruct.BusiInfoVo> getData(@GetJsonValue(zh = "数据ID") String busiInfoId) {
        return ReturnVo.buildSuccess(baseBusiInfoService.getDetailVo(busiInfoId));
    }
}
